package Model;

import java.util.ArrayList;

public class User extends Record {
    private String password;
    private boolean status;
    private ArrayList<Order> orders = null;

    public User(){
        status = false;
    }

    public User(String name, String password){
        status = false;

        this.name = name;
        this.password = password;
    }

    public boolean getStatus(){
        return status;
    }

    String getPassword(){
        return password;
    }

    public void setStatus(String name, String password){
        if( this.name.equals(name) && this.password.equals(password) ){
            this.status = true;
        }
    }

    public void refreshProductList(){
        UserM userM = new UserM();
        orders = userM.getOrders(this.id);
    }

    public ArrayList<Order> getOrders(){
        if( orders == null ){
            refreshProductList();
        }

        return orders;
    }

    public boolean buy(int pid, int amount, float price){
        UserM userM = new UserM();

        boolean status = userM.buy(this.id, pid, amount, price);
        refreshProductList();

        return status;
    }
}
